//
//  GetTicketCell.m
//  TerritoryShopkeeper
//
//  Created by xiaowu on 2017/12/12.
//  Copyright © 2017年 ZDQK. All rights reserved.
//

#import "GetTicketCell.h"

@implementation GetTicketCell

+ (CGFloat)getHeight:(NSMutableArray <CouponModel *> *)arr {
    if (arr.count > 0) {
        return 44;
    }
    return 0;
}

- (void)setTicketValueWith:(NSMutableArray<CouponModel *> *)array {
    if (array.count == 0) {
        [self.rightArrowImage setHidden:YES];
        [self.titleLabel setHidden:YES];
        [self.lineView setHidden:YES];
    } else {
        [self.rightArrowImage setHidden:NO];
        [self.titleLabel setHidden:NO];
        [self.lineView setHidden:NO];
    }
    
    for (UIView *view in self.contentView.subviews) {
        if ([view isKindOfClass:[UILabel class]] && view != self.titleLabel) {
            [view removeFromSuperview];
        }
    }
    
    CGFloat labelHeight = 16;
    CGFloat labelComment = 10;
    CGFloat startY = 14;
    CGFloat startX = self.titleLabel.right+labelComment;
    for (NSInteger i = 0; i < array.count; i++) {
        CouponModel *model = array[i];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(startX, startY, 10, labelHeight)];
        [label setFont:TextPingFangFontSize(12)];
        [label setTextColor:[UIColor whiteColor]];
        [label setTextAlignment:NSTextAlignmentCenter];
        [label setCircleWithColor:[UIColor clearColor] borderWidth:0 cornerRadius:2.0];
        [label setBackgroundColor:[UIColor ThemeColor]];
        [label setText:[NSString stringWithFormat:@"满%@减%@",model.cfull,model.creduce]];
        [label sizeToFit];
        label.height = labelHeight;
        label.width += 6;
        if (label.right > self.width-34) {
            return;
        }
        [self.contentView addSubview:label];
        startX += (label.width+labelComment);
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.titleLabel.font = TextPingFangFontSize(14);
    self.titleLabel.textColor = [UIColor grayTextColor];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
@end
